import type { IQuery, TableConfig } from '@/api/config/types';
import type { AxFiles } from '@/api/modules/ax/files/types';
import { filesDelete, filesEdit } from './curd';
import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue';
import { hasPerm } from '@/utils/common/perm';

//查询参数接口
interface FilesQuery {
  fileName: string;
  filePath: string;
  fileSize: string;
  fileType: string;
  fileDescription: string;
}

let queryObj: IQuery<FilesQuery> = {
  pageNum: 1,
  pageSize: 10,
  total: 0,
  fileName: '',
  filePath: '',
  fileSize: '',
  fileType: '',
  fileDescription: '',
  orderByColumn: 'create_time',
  isAsc: 'desc',
};

const resetFilesQuery = () => {
  filesTable.value.query = {
    ...queryObj,
  };
};

export const filesTable = ref<TableConfig<AxFiles>>({
  //勾选的唯一标识,数据库主键
  rowKey: 'fileId',
  data: [],
  loading: false,
  //必须唯一，存储窗口位置，表头等
  moduleName: 'AxFiles',
  viewMode: 'card',
  keys: [],
  query: queryObj,
  contextmenu: [
    {
      title: '编辑',
      label: '编辑',
      key: 'list',
      onClick() {
        filesEdit();
      },
      icon: h(EditOutlined),
      disabled: hasPerm('ax:files:files'),
    },
    {
      title: '删除',
      label: '删除',
      key: 'delete',
      icon: h(DeleteOutlined),
      onClick() {
        filesDelete();
      },
      disabled: hasPerm('ax:files:remove'),
    },
  ],
  reset: resetFilesQuery,
});
